package sendmethodinterfacelogic

import (
	"context"

	"dfx_cmdb/cmdb-sendmsg-rpc/internal/svc"
	cmdb_database_sync "dfx_cmdb/cmdb-sendmsg-rpc/types/cmdb-database-sync"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateSendMethodLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateSendMethodLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateSendMethodLogic {
	return &UpdateSendMethodLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// UpdateSendMethod 更新指定的发送方式配置
func (l *UpdateSendMethodLogic) UpdateSendMethod(in *cmdb_database_sync.SendMethodInfo) (*cmdb_database_sync.PublicMsgResponse, error) {
	// todo: add your logic here and delete this line
	// tx := l.svcCtx.DB
	// err := tx.Model(&cmdbsendmsg.SendMethod{}).Where("id = ?", in.ID).First(&cmdbsendmsg.SendMethod{}).Error
	// if err != nil {
	// 	return &cmdb_database_sync.PublicMsgResponse{
	// 		Msg: "发送方式不存在",
	// 	}, errors.New("发送方式已存在")
	// }

	// sendMsg := cmdbsendmsg.SendMethod{
	// 	Models: models.Models{
	// 		Id: in.ID,
	// 	},
	// 	SendUrl:        in.SendUrl,
	// 	SendMethodType: in.SendMethodType,
	// 	CloudId:        uint32(in.CloudId),
	// 	TemplateID:     uint32(in.TemplateID),
	// }
	// err = models.UpdateDatabase(tx, sendMsg, map[string]interface{}{"id": in.ID})
	// if err != nil {
	// 	return &cmdb_database_sync.PublicMsgResponse{
	// 		Msg: "更新发送方式失败",
	// 	}, errors.New("发送方式已存在")
	// }
	return &cmdb_database_sync.PublicMsgResponse{
		Msg: "更新发送方式成功",
	}, nil
}
